package generateur;

import java.io.StringWriter;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

import constructeurEleve.EvaluationEleve;
import constructeurEvaluation.Evaluation;
import constructeurReponse.EvaluationReponse;

/**
 * This class is used to generate 3 xml file contents :
 * <br> - eval : the evaluation file
 * <br> - evalE : the student evaluation file
 * <br> - evalR : the response file
 *
 */
public class GenerateurXML {
	
	
	/**
	 * This method will generate a xml content file
	 * @param eval : the evaluation object
	 * @return a new eval xml content
	 */
	public String generateurXmlEval(Evaluation eval) {
		JAXBContext jaxbContext;
		StringWriter strEval = new StringWriter();
		
		try {
			jaxbContext = JAXBContext.newInstance("constructeurEvaluation");
			Marshaller marshaller = jaxbContext.createMarshaller();
			marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
					new Boolean(true));
			marshaller.marshal(eval,strEval);
			
		} catch (JAXBException e) {
			e.printStackTrace();
		}
		
		return strEval.toString();
	}
	
	/**
	 * This method will generate a xml content file
	 * @param evalE : the student evaluation object
	 * @return a new student eval xml content
	 */
	public String generateurXmlEvalEleve(EvaluationEleve evalE) {
		JAXBContext jaxbContext;
		StringWriter strEleve = new StringWriter();
		
		try {
			jaxbContext = JAXBContext.newInstance("constructeurEleve");
			Marshaller marshaller = jaxbContext.createMarshaller();
			marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
					new Boolean(true));
			marshaller.marshal(evalE,strEleve);
			
		} catch (JAXBException e) {
			e.printStackTrace();	
		}
		return strEleve.toString();
	}
	
	/**
	 * This method will generate a xml content file
	 * @param evalR : the response object
	 * @return a new response xml content
	 */
	public String generateurXmlEvalReponse(EvaluationReponse evalR) {
		JAXBContext jaxbContext;
		StringWriter strReponse = new StringWriter();
		
		try {
			jaxbContext = JAXBContext.newInstance("constructeurReponse");
			Marshaller marshaller = jaxbContext.createMarshaller();
			marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
					new Boolean(true));
			marshaller.marshal(evalR,strReponse);
			
		} catch (JAXBException e) {
			e.printStackTrace();	
		}
		return strReponse.toString();

	}
}
